package ch02;
import java.util.Scanner;
/**
 * @author chenmin
 * @desc TODO
 * @date 2025/9/2
 */

class If1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入第一个数字: ");
        double num1 = scanner.nextDouble();
        System.out.print("请输入运算符 (+, -, *, /): ");
        String operator = scanner.next();
        System.out.print("请输入第二个数字: ");
        double num2 = scanner.nextDouble();
        double result;
        if ("+".equals(operator)) {
            result = num1 + num2;
        } else if ("-".equals(operator)) {
            result = num1 - num2;
        } else if ("*".equals(operator)) {
            result = num1 * num2;
        } else if ("/".equals(operator)) {
            if (num2 == 0) {
                System.out.println("除数不能为0");
                return;
            }
            result = num1 / num2;
        } else {
            System.out.println("无效的运算符");
            return;
        }
        System.out.printf("%.2f %s %.2f = %.2f%n", num1, operator, num2, result);
        scanner.close();
    }
}
